import { request } from '@umijs/max';
import { PageResponse } from './index';

export interface AnnouncementInfo {
  id?: number;
  title: string;
  content: string;
  type: 1 | 2 | 3;  // 1-普通公告,2-重要公告,3-紧急公告
  status: 0 | 1;  // 0-未发布,1-已发布
  priority: number;
  startTime?: string;
  endTime?: string;
  isTop: 0 | 1;
  viewCount: number;
  famousPersonId: number;
}

export interface AnnouncementPageRequest {
  pageCurrent: number;
  pageSize: number;
  famousPersonId: number;
  keyword?: string;
  type?: number;
  status?: number;
}

export async function getAnnouncementPage(params: AnnouncementPageRequest) {
  return request<PageResponse<AnnouncementInfo>>('/announcement/page', {
    method: 'POST',
    data: params,
  });
}

export async function addAnnouncement(data: Omit<AnnouncementInfo, 'id'>) {
  return request('/announcement/back', {
    method: 'POST',
    data,
  });
}

export async function updateAnnouncement(data: AnnouncementInfo) {
  return request('/announcement/back', {
    method: 'PUT',
    data,
  });
}

export async function deleteAnnouncement(idList: number[]) {
  const ids = idList.join(',');
  return request(`/announcement/back/${ids}`, {
    method: 'DELETE',
  });
} 